<?

require_once("edu/utah/hazards/dmsd/entity/Project.php");
require_once("edu/utah/hazards/dmsd/entity/Projects.php");
require_once("edu/utah/hazards/dmsd/json/ProjectParser.php");

class ProjectsParser
{
	
	private $projects;
	
	/**
	 * Parses JSON data to/from a <Projects>
	 */
	public function ProjectsParser()
	{
		$this->projects = new Projects();		
	}
	
	/**
	 * Convert JSON into a <Projects> containing <Project>s
	 */
	public function unmarshall($data)
	{
		$this->projects->setLimit( $data->limit );
		$this->projects->setQuery( $data->query );
		$projectParser = new ProjectParser();
		for ($index = 0; $index < sizeof($data->data); $index++) {
			$projectData = $data->data[$index];
			$project = $projectParser->unmarshall( $projectData );
			$this->projects->addProject( $project ); 
		}
		return $this->projects;
		
	}
	
	/**
	 * Convert a <Projects> into a JSON hash
	 */
	public function marshall( $projects )
	{
		$data;
		$data->class = "Projects";
		$data->limit = $projects->getLimit();
		$list = $projects->getProjects();
		$projectParser = new ProjectParser();
		for ($index = 0; $index < sizeof($list); $index++) {
			$project = $list[$index];
			$marshalledProject = $projectParser->marshall( $project );
			$data->projects[$index] = $marshalledProject;
		}
		return ($data);
		
	}
	
}


?>